
<h2 style='text-align:center'>砍价商品管理</h2>
<div id='MainFreeGoods_GoodsListArea'>
	<div style='display:flex'>
		<div style='flex:1'>
			<input type="text" id='MainFreeGoods_SearchInp' style='width:100%' />
		</div>
		<div>
			<button type='button' id='MainFreeGoods_SearchBtn'>搜索</button>
		</div>
	</div>
	<select id="MainFreeGoods_TypeSelect" style='width:100%'>
		<option value="all">全部</option>
		<option value="1">正常</option>
		<option value="2">已下架</option>
		<option value="3">已封禁</option>
	</select>


	<!--商品列表-->
	<div id='MainFreeGoods_GoodsList'></div>


	<!--分页-->
	<div id='MainFreeGoods_GoodsFpage' style='text-align:center;margin:20px auto'></div>


</div>



<script>


if(!sessionStorage.FreeGoods_pnow){			//当前页
	sessionStorage.FreeGoods_pnow = 1;		
}

if(!sessionStorage.FreeGoods_pMax){			//当前最大页
	sessionStorage.FreeGoods_pMax = 2;
}


if(!sessionStorage.FreeGoods_search){		//搜索值
	sessionStorage.FreeGoods_search = '';
}

function _resetFreeGoodsSess(type){				//重置本页相关参数
	sessionStorage.FreeGoods_pnow = 1;
	sessionStorage.FreeGoods_pMax = 2;
	if(type == 1){
		sessionStorage.FreeGoods_search = '';
		$('#MainFreeGoods_SearchInp').val('');
	}
}

_mainFreeGoodsInit();


function GetCurrentType(){	//获取当前选择的分类
	return $('#MainFreeGoods_TypeSelect').find('option:selected').val();
}


$('#MainFreeGoods_TypeSelect').change(function(){	//类型选择事件
	_resetFreeGoodsSess(1);
	_mainFreeGoodsInit();
});


$('#MainFreeGoods_SearchBtn').click(function(){		//搜索按钮点击事件
	_resetFreeGoodsSess();
	sessionStorage.FreeGoods_search = $('#MainFreeGoods_SearchInp').val().trim();
	_mainFreeGoodsInit();
});


function _mainFreeGoodsInit(){
	_freeGoods_getList(function(data){
		_freeGoods_getList_parse(data);
	});
}



function _freeGoods_getList(fun){		//获取砍价商品列表
	var data = {
		type:'freeGoods_getListFull',
		pnow:sessionStorage.FreeGoods_pnow,
		search:sessionStorage.FreeGoods_search,
		get_type:GetCurrentType()
	}
	AjaxAdmin(data,function(res){
		var tmp = _checkJsonFormat(res);
		fun(tmp.data);
	});
}

//解析砍价列表数据到元素

function _freeGoods_getList_parse(info){
	var str = '';
	if(typeof(info) != 'object' || info.length < 1){
		if(sessionStorage.FreeGoods_pnow == 1){	//首页就没数据则显示，暂无数据
			$('#MainFreeGoods_GoodsList').html('暂无数据！');
		}else{ 	//后页无数据
			sessionStorage.FreeGoods_pnow = sessionStorage.FreeGoods_pnow - 1;
			sessionStorage.FreeGoods_pMax = sessionStorage.FreeGoods_pnow;
		}
	}else{
		for(var i=0;i<info.length;i++){
			str += "<div style='display:flex;border-bottom:1px solid #ccc;font-size:13px;margin:15px 0;'>";
			str += "<div style='border:1px solid #eff;width:100px;height:100px'>";
			if(info[i].banner){
				var img_addr = upyun_shop_img+info[i].banner;
			}else{
				var img_addr = '../Public/Image/base.png';
			}
			str += "<img src='"+img_addr+"' style='width:100%;height:100%' onerror=this.src='../Public/Image/base.png' alt='呵呵了' ></div>";
			str += "<div style='flex:1;padding:0 5px;box-sizing:border-box;color:#999'>";
			//标题
			str += "<div style='font-size:14px;word-break:break-all;overflow:hidden;color:#333'>标题："+info[i].title+"</div>";		
			
			//价格
			str += "<div style='overflow:hidden;margin:8px 0'>价格："+info[i].price+"</div>";

			//商品详情
			str += "<div style='display:flex;width:330px;border:0px solid;margin:8px 0'><div style='width:40px;'>详情：</div><div class='freeGoodsInfo' style='flex:1;overflow:hidden;white-space:nowrap;word-break:break-all'>"+info[i].info+"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa要a</div></div>";

			str += "<div style='height:20px;display:flex'>";
			//状态
			var stat_view = '<span style="color:#fff">封禁</span>';
			switch(info[i].free_stat){
				case 1:case '1':
					var stat_str = '<text style="color:blue">正常</text>';
					break;
				case 2:case '2':
					var stat_str = '已下架';
					break;
				case 3:case '3':
					var stat_str = '<text style="color:red">已封禁</text>';
					var stat_view = '<span style="color:red">解封</span>';
					break;
			}
			str += "<div style=''>状态：<span>"+stat_str+"</span></div>";

			str += "<div style='flex:1;text-align:right'>";


			str += "<span style='padding:1px 7px;background:#aaf;border-radius:5px' onclick=_freeGoodsStop("+info[i].free_id+","+info[i].free_stat+")>"+stat_view+"</span>　";


			str += "<span style='padding:1px 7px;background:#aaf;color:#fff;border-radius:5px' 	onclick=FreeCon_FreeGoodsOrders("+info[i].free_id+")>查看订单</span>　";
			str += "</div></div></div></div>";
		}
		$('#MainFreeGoods_GoodsList').html(str);

		//展示或隐藏商品信息
		$('.freeGoodsInfo').click(function(){
			var space = $(this).css('white-space');
			if(space == 'normal'){
				$(this).css('white-space','nowrap');
			}else{
				$(this).css('white-space','normal');
			}
		})
	}

	Fpage(sessionStorage.FreeGoods_pnow,sessionStorage.FreeGoods_pMax,function(p){
		C(p);
		sessionStorage.FreeGoods_pnow = p;
		sessionStorage.FreeGoods_pMax = p + 1;
		_mainFreeGoodsInit();
	},1,1,'#MainFreeGoods_GoodsFpage')

}



//查看砍价商品下的订单列表
function FreeCon_FreeGoodsOrders(free_id){
	sessionStorage.admin_formFreeGoodsId = free_id;	//标记是从砍价商品页跳转到订单页
	$('#Main_Nav').val('Main_FreeGoodsOrder');
	//跳转到砍价订单页
//	sessionStorage.store_mainCurrentNavPage = 'controlFreeOrder';
//	$('#Index_Nav').val('controlFreeOrder');
	_loadPage()
}









//封禁或解封砍价商品
function _freeGoodsStop(free_id,free_stat){
	var data = {
		type:'freeGoodsStop',
		free_id:free_id,
		free_stat:free_stat
	}
	AjaxAdmin(data,function(res){
		var tmp = _checkJsonFormat(res);
		if(tmp.stat == 'ok'){
			A('操作成功！');
			_mainFreeGoodsInit();
		}else{
			A('操作异常！');
		}
	})
}







	// GetFreeGoodsList();



	// //解析砍价列表数据到元素
	// function Parse_mfg_info(){
	// 	var str = '';
	// 	for(var i=0;i<mfg_info.length;i++){
	// 		str += "<div style='display:flex;border-bottom:1px solid #fee;font-size:13px;margin:15px 0;'>";
	// 		str += "<div style='border:1px solid #eef;width:100px;height:100px'>";
	// 		if(mfg_info[i].banner){
	// 			var img_addr = upyun_shop_img+mfg_info[i].banner;
	// 		}else{
	// 			var img_addr = '../Public/Image/base.png';
	// 		}
	// 		str += "<img src='"+img_addr+"' style='width:100%;height:100%' onerror=this.src='../Public/Image/base.png' alt='呵呵了' ></div>";
	// 		str += "<div style='flex:1;padding:0 5px;box-sizing:border-box;color:#999'>";
	// 		//标题
	// 		str += "<div style='font-size:14px;height:40px;word-break:break-all;overflow:hidden;color:#333'>"+mfg_info[i].title+"</div>";		
	// 		str += "<div style='height:20px;display:flex;margin:8px 0'>";
	// 		//价格
	// 		str += "<div style='flex:1;color:red;font-weight:bold'>￥："+mfg_info[i].price+"</div>";
	// 		str += "</div>";

	// 		str += "<div style='height:20px;display:flex'>";
	// 		//状态
	// 		switch(mfg_info[i].free_stat){
	// 			case 1:case '1':var stat_str = '<text style="color:blue">正常</text>';break;
	// 			case 2:case '2':var stat_str = '已封禁';break;
	// 			default :
	// 				var stat_str = '审核中';break;
	// 		}
	// 		str += "<div style='width:60px'>"+stat_str+"</div>";

	// 		str += "<div style='flex:1;text-align:right'>";
	// 		if(mfg_info[i].free_stat == 1){
	// 			str += "<span style='padding:1px 7px;background:#aaf;color:#fff;border-radius:5px' onclick=FreeGoodsDisabled("+mfg_info[i].id+")>封禁</span>　";
	// 		}
	// 		str += "<span style='padding:1px 7px;background:#aaf;color:#fff;border-radius:5px' 	onclick=FreeCon_FreeGoodsOrders("+mfg_info[i].id+")>查看订单</span>　";
	// 		str += "</div></div></div></div>";
	// 	}
	// 	$('#MainFreeGoods_GoodsList').html(str);
	// }


	// //封禁砍价商品
	// function FreeGoodsDisabled(id){



	// 	var data = {
	// 		type:'ChangeFreeGoodsStat',
	// 		id:id,
	// 		stat:2
	// 	};
	// 	Ajax2(data,function(res){
	// 		if(res && res > 0){
	// 			A('操作成功！');
	// 			for(var i=0;i<mfg_info.length;i++){
	// 				if(mfg_info[i].id == id){
	// 					mfg_info[i].free_stat = 2;
	// 				}
	// 			}
	// 			Parse_mfg_info();
	// 		}else{
	// 			A('操作异常！');
	// 		}
	// 	});
	// }

</script>